    /** 
     * @function escapeHTML 转义html脚本 < > & " ' 
     * @param a - 
     *            字符串 
     */  
    function escapeHTML(a){  
        a = "" + a;  
        return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, '&quot;').replace(/'/g, "&apos;");
    }
    /** 
     * @function unescapeHTML 还原html脚本 < > & " ' 
     * @param a - 
     *            字符串 
     */  
    function unescapeHTML(a){  
        a = "" + a;  
        return a.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");  
    }

    var menuCell = 5;// 导航菜单的间隔像素
    function initMenuHtml(menuData){
        var data = menuData;
        var liStr = '';
        // 遍历生成主菜单
        for( var i = 0; i < data.length; i++){
            // 判断是否存在子菜单
            if(data[i].sub != null && data[i].sub.length > 0){
                liStr += '<li class="layui-nav-item nav-item">';
                liStr += '<a lay-href="javascript:;" lay-tips="' + data[i].alt + '" data-id="' + data[i].id + '" data-title="' + data[i].alt + '"><i class="layui-icon layui-icon-"' + data[i].icon + '></i><cite>' + data[i].alt + '</cite></a>';
                liStr += '<dl class="layui-nav-child">';
                // 遍历获取子菜单
                for( var k = 0; k <data[i].sub.length; k++){
                    liStr += getSubMenu(data[i].sub[k]);
                }
                liStr += "</dl></li>";
            }else{
                liStr += '<li class="layui-nav-item nav-item"><a lay-href="javascript:;" lay-tips="' + data[i].alt + '" data-id="' + data[i].id + '" data-title="' + data[i].alt + '"><i class="layui-icon layui-icon-"' + data[i].icon + '></i><cite>' + data[i].alt + '</cite></a></li>';
            }
        };
        return '<ul class="layui-nav layui-nav-tree" lay-filter="test">' + liStr + '</ul>';
    }
    
    // 递归生成子菜单
    function getSubMenu(childMenu, num=0) {
        num++;
        var childStr = '';
        if(childMenu.sub != null && childMenu.sub.length > 0){
            childStr += '<dd><ul><li class="layui-nav-item">';
            childStr += '<a lay-href="javascript:;" lay-tips="' + childMenu.alt + '" lay-direction="' + num + '" data-id="' + childMenu.id + '" data-title="' + childMenu.alt + '" style="margin-Left:"' + num*menuCell + 'px"><i class="layui-icon layui-icon-"' + childMenu.icon + '></i><cite>' + childMenu.alt + "</cite></a>";
            childStr += '<dl class="layui-nav-child">';
            for( var j = 0; j < childMenu.sub.length; j++){
                childStr += getSubMenu(childMenu.sub[j], num);
            }
            childStr += '</dl></li></ul></dd>';
        }else{
            childStr += '<dd><a lay-href="' + childMenu.url + '" lay-tips="' + childMenu.alt + '" data-id="' + childMenu.id + '" data-title="' + childMenu.alt + '" style="margin-Left:' + num*menuCell + 'px"><i class="layui-icon layui-icon-"' + childMenu.icon + '></i><cite>' + childMenu.alt + '</cite></a></dd>';
        }
        return childStr;
    }

    /** 
     * json格式转树状结构 
     * @param   {json}      json数据 
     * @param   {String}    id的字符串 
     * @param   {String}    父id的字符串 
     * @param   {String}    children的字符串 
     * @return  {Array}     数组 
     */  
    function transData(a, idStr, pidStr, chindrenStr){  
        var r = [], hash = {}, id = idStr, pid = pidStr, children = chindrenStr, i = 0, j = 0, len = a.length;  
        for(; i < len; i++){  
            hash[a[i][id]] = a[i];  
        }  
        for(; j < len; j++){  
            var aVal = a[j], hashVP = hash[aVal[pid]];  
            if(hashVP){  
                !hashVP[children] && (hashVP[children] = []);  
                hashVP[children].push(aVal);  
            }else{  
                r.push(aVal);  
            }  
        }  
        return r;  
    }